Generalize error message used by both `cargo package` and `cargo publish`.
authorBinary Birch Tree <binarybirchtree@users.noreply.github.com>
Sat, 3 Sep 2016 01:05:26 +0000 (21:05 -0400)
committerBinary Birch Tree <binarybirchtree@users.noreply.github.com>
Sat, 3 Sep 2016 01:05:26 +0000 (21:05 -0400)
src/cargo/ops/cargo_package.rs
tests/package.rs
tests/publish.rs

index 78fde8ed7dd8eae8ce031b8f1270eef605dc612b..dc12e46ffe8b8c992447808063d07dca63f3be11 100644 (file)
@@ -173,8 +173,7 @@ fn check_not_dirty(p: &Package, src: &PathSource) -> CargoResult<()> {
             Ok(())
         } else {
             bail!("{} dirty files found in the working directory:\n\n{}\n\n\
-                   to publish despite this, pass `--allow-dirty` to \
-                   `cargo publish`",
+                   to proceed despite this, pass the `--allow-dirty` flag",
                   dirty.len(), dirty.join("\n"))
         }
     }
index d23cc539aabbfc619eecacbf401b57052e9ae634..7f3712f372425f8dc1ce9c46a9fbfe1a0816bfe2 100644 (file)
@@ -6,7 +6,7 @@ extern crate hamcrest;
 extern crate tar;
 extern crate cargo;
 
-use std::fs::File;
+use std::fs::{File, OpenOptions};
 use std::io::prelude::*;
 use std::path::{Path, PathBuf};
 
@@ -544,3 +544,37 @@ Caused by:
   [..]
 "));
 }
+
+#[test]
+fn do_not_package_if_repository_is_dirty() {
+    // Create a Git repository containing a minimal Rust project.
+    git::repo(&paths::root().join("foo"))
+        .file("Cargo.toml", r#"
+            [project]
+            name = "foo"
+            version = "0.0.1"
+            license = "MIT"
+            description = "foo"
+            documentation = "foo"
+            homepage = "foo"
+            repository = "foo"
+        "#)
+        .file("src/main.rs", "fn main() {}")
+        .build();
+
+    // Modify Cargo.toml without committing the change.
+    let p = project("foo");
+    let manifest_path = p.root().join("Cargo.toml");
+    let mut manifest = t!(OpenOptions::new().append(true).open(manifest_path));
+    t!(writeln!(manifest, ""));
+
+    assert_that(p.cargo("package"),
+                execs().with_status(101)
+                       .with_stderr("\
+error: 1 dirty files found in the working directory:
+
+Cargo.toml
+
+to proceed despite this, pass the `--allow-dirty` flag
+"));
+}
index eb3221b63151ca45d43e9f57f91d67a26f261907..b11cb7a47d64ef1ad584983f0ee90df7eb5cc546 100644 (file)
@@ -207,7 +207,7 @@ error: 1 dirty files found in the working directory:
 
 bar
 
-to publish despite this, pass `--allow-dirty` to `cargo publish`
+to proceed despite this, pass the `--allow-dirty` flag
 "));
 }